import numeral from 'numeral'
import NP from 'number-precision'

const MyPlugin = {
  install: function (app, options) {
    app.config.globalProperties.$formatMoney = function (fen) {
      if (!fen && fen !== 0) return ''
      let yuan = NP.divide(fen, 100)
      return numeral(yuan).format('0,0.00')
    }

    app.config.globalProperties.$textBool = function (val) {
      if (!val || val == '0') {
        return '否'
      }
      return '是'
    }

    app.config.globalProperties.$textActive = function (val) {
      if (val == 0) {
        return '禁用'
      }
      return '启用'
    }

    app.config.globalProperties.$elType = function (val) {
      const types = ['primary', 'success', 'info', 'warning', 'danger', '']
      const index = id % 6
      return types[index]
    }

    app.config.globalProperties.$openApp = function () {
      const agent = navigator.userAgent
      if (agent.match(/(iPhone|iPod|iPad);?/i)) {
        window.location.href = 'com.xhk.yabai://' //ios app协议
        // window.location.href = "org.reactjs.native.xidebaoapp://"
        window.setTimeout(function () {
          window.location.href = 'http://qky.cdgxdb.com/'
        }, 1000)
      }
      else if (agent.match(/android/i)) {
        window.location.href = 'launch://com.xhk.yabai' //android app协议
        // window.location.href = "xidebao://hhjt.happybaby"
        window.setTimeout(function () {
          window.location.href = 'http://qky.cdgxdb.com/'
        }, 1000)
      }
      else {
          window.location.href = 'http://qky.cdgxdb.com/'
      }
    }
  },
}

export default MyPlugin
